package com.platform.metamodel;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

/**
 * @author liujizheng
 * @version 1.0
 * @name ContextMappings
 * @Desc 映射配置
 * @date 2022/3/8 16:33
 */
public class ContextMappings implements Mappings<ContextMappings> {
    private final Map<String, Function<String, String>> keyFunction;
    private final Map<Object, Function<Object, Object>> valueFunction;

    ContextMappings() {
        keyFunction = new HashMap<>(8);
        valueFunction = new HashMap<>(8);
    }

    /**
     * 添加映射配置
     *
     * @param key       键值
     * @param keyMapper 键映射
     * @param valueMapper 值映射
     * @return mappings
     */
    @Override
    public ContextMappings addMapper(String key, Function<String, String> keyMapper, Function<Object, Object> valueMapper) {
        keyFunction.put(key, keyMapper);
        valueFunction.put(key, valueMapper);
        return this;
    }

    Function<String, String> keyFunction(String key) {
        return keyFunction.get(key);
    }

    Function<Object, Object> valueFunction(String key) {
        return valueFunction.get(key);
    }
}
